package com.lovo.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.sys.bean.UserOrderBean;
import com.lovo.sys.service.IUserOrderService;
import io.swagger.models.auth.In;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("userOrder")
public class UserOrderController {
    @Autowired
    private IUserOrderService userOrderService;

    @GetMapping("findByItem")
    public IPage<UserOrderBean> findByItem(Integer pageNum) {
        return userOrderService.findByItem(pageNum);
    }

    @GetMapping("findAll")
    public IPage<UserOrderBean> findAll(Integer pageNum) {
        return userOrderService.findAll(pageNum);
    }

    @GetMapping("findByDateAndType")
    public IPage<UserOrderBean> findByDateAndType(String Date, String type, Integer pageNum, Integer status) {
        return userOrderService.findByDateAndType(Date, type, pageNum, status);
    }

    @GetMapping("findByUserOrderId")
    public UserOrderBean findByUserOrderId(String idNum) {
        return userOrderService.findByUserOrderId(idNum);
    }

    @GetMapping("deleteByUserOrderId")
    public String deleteByUserOrderId(long UserOrderId) {
        userOrderService.deleteByUserOrderId(UserOrderId);
        return "ok";
    }

    @GetMapping("addUserOrder")
    public String addUserOrder(UserOrderBean userOrderBean) {
        userOrderService.addUserOrder(userOrderBean);
        return "ok";
    }

    @GetMapping("updateUserOrder")
    public String updateUserOrder(Integer userOrderId, Integer num) {
        userOrderService.updateUserOrder(userOrderId, num);
        return "ok";
    }

    @GetMapping("SalesReturn")
    public String SalesReturn(Integer userOrderId, Integer num, Integer goodsNum, String goodsName) {
        userOrderService.SalesReturn(userOrderId, num, goodsNum, goodsName);
        return "ok";
    }

    @GetMapping("findAllType")
    public List<String> findAllType() {
        return userOrderService.findAllType();
    }

    @GetMapping("updateStatus")
    public boolean updateStatus(@RequestParam("orderNum") String orderNum, @RequestParam("num") Integer num, @RequestParam("payDate") String payDate) {
        try {
            userOrderService.updateStatus(orderNum, num,LocalDate.parse(payDate));
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
